package com.androidx.p013lv.base.utils;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Environment;
import android.provider.MediaStore;
import com.androidx.p013lv.base.BaseSdk;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

/* renamed from: com.androidx.lv.base.utils.ImageUtil */
public class ImageUtil {
    public static void saveImageToGallery(Context context, Bitmap bitmap) {
        File file = new File(Environment.getExternalStorageDirectory().getPath() + "/pic_file");
        if (!file.exists()) {
            file.mkdir();
        }
        String str = System.currentTimeMillis() + ".jpg";
        File file2 = new File(file, str);
        try {
            FileOutputStream fileOutputStream = new FileOutputStream(file2);
            bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fileOutputStream);
            fileOutputStream.flush();
            fileOutputStream.close();
            MediaStore.Images.Media.insertImage(context.getContentResolver(), file2.getAbsolutePath(), str, (String) null);
            context.sendBroadcast(new Intent("android.intent.action.MEDIA_SCANNER_SCAN_FILE", Uri.fromFile(file2)));
            ToastUtils.getInstance().showCorrect("保存成功");
        } catch (Exception e) {
            e.printStackTrace();
            ToastUtils.getInstance().showSigh("保存失敗");
        }
    }

    public static boolean saveImageToGallery(Context context, Bitmap bitmap, String str) {
        File file = new File(context.getFilesDir().getAbsolutePath() + File.separator + "qrcode");
        if (!file.exists()) {
            file.mkdir();
        }
        File file2 = new File(file, str);
        try {
            FileOutputStream fileOutputStream = new FileOutputStream(file2);
            boolean compress = bitmap.compress(Bitmap.CompressFormat.JPEG, 80, fileOutputStream);
            fileOutputStream.flush();
            fileOutputStream.close();
            context.sendBroadcast(new Intent("android.intent.action.MEDIA_SCANNER_SCAN_FILE", Uri.fromFile(file2)));
            if (compress) {
                return true;
            }
            return false;
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }
    }

    public static int getResource(String str) {
        return UiUtils.getResources().getIdentifier(str, "drawable", BaseSdk.getContext().getPackageName());
    }
}
